/******************************************************************
 * This program was written as part of
 *   Assignment 4
 *   Computer Graphics                                             
 *   Semester 1, 2013
 *   School of Computer Science,
 *   The University of Adelaide
 *                                                                          
 * I declare that all material in this assessment is my own work except where
 * there is clear acknowledgement and reference to the work of others. I have
 * read the University Policy Statement on Plagiarism, Collusion and Related
 * Forms of Cheating:  

 * http://www.adelaide.edu.au/policies/?230

 * I give permission for my assessment work, including my subversion
 * repository, to be reproduced and submitted to academic staff for the
 * purposes of assessment and to be copied, submitted and retained in a form
 * suitable for electronic checking of plagiarism.  
                            
 * Authors:
 *  Terry Moschou    a1208955
 *  Salih Al-Rashid  a1210108
 *  Ben McAleer      a1212203
*******************************************************************/

#include "Equipment.hpp"
#include "Model.hpp"
#include "Context.hpp"
#include "Terrain.hpp"
#include "Scene.hpp"

const mat4 armmat = glm::rotate(glm::translate(mat4(1.0f), vec3(0.125f,-0.75f,-0.125f)),90.0f,vec3(-1.0f,0.0f,0.0f));

Equipment::Equipment(Object * parent, Model * model, mat4 matrix, int type)
  : Object(parent, matrix, model, "Equipment")
{
  m_type = type;
  m_modelMatrix = matrix;
  m_equipped = false;
}

void Equipment::update() {

  m_pos.y = g_context.m_scene->m_terrain->getHeight(m_pos.x, m_pos.z);
  
  if(m_equipped)
    setModelMatrix(armmat);
  else
    setModelMatrix(glm::rotate(glm::translate(mat4(1.0f), m_pos),m_rot,vec3(0.0f,1.0f,0.0f)) * m_modelMatrix);
  
  Object::update();
}
